
//引入路由组件
import Home from "@/pages/Home"
import Search from "@/pages/Search"
import Login from "@/pages/Login"
import Register from "@/pages/Register"
import Detail from "@/pages/Detail"
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'


// 引入二级组件
import MyOrder from '@/pages/Center/myOrder'
import GroupOrder from '@/pages/Center/groupOrder'

// 路由配置信息
export default 
    [
        {    //  首页页面
            path: '/home',
            component: Home,
            meta: { show: true }
        },
        {  //  搜索页面
            name: 'search',  
            path: '/search/:keyword?',
            component: Search,
            meta: { show: true }
        },
        {  //  登录页面
            path: '/login',
            component: Login,
            meta: { show: false }
        },
        {  //  注册页面
            path: '/register',
            component: Register,
            meta: { show: false }
        },
        {  //  产品详情页面
            path: '/detail/:skuid',
            component: Detail,
            meta: { show: true }
        },
        {   // 加入购物车成功页面
            path: '/addcartsuccess',
            name: 'addcartsuccess',
            component: AddCartSuccess,
            meta: { show: true }
        },   
        {   //  购物车页面
            path: '/shopcart',
            component: ShopCart,
            meta: { show: true }
        },
        {   //  支付页面
            path: '/trade',
            component: Trade,
            meta: { show: true },
            // 路由守卫
            beforeEnter: (to, from, next) => {
                if (from.path == '/shopcart') {
                    next();
                } else {
                    next(false)
                }
            }
        },
        {   //  确认支付页面支付页面
            path: '/pay',
            component: Pay,
            meta: { show: true },
            beforeEnter: (to, from, next)=>{
                if (from.path == '/trade') {
                    next()
                } else {
                    next(false)
                }
            }
        },
        {   //  支付成功页面
            path: '/paysuccess',
            component: PaySuccess,
            meta: { show: true }
        },
        {   //  个人中心页面
            path: '/center',
            component: Center,
            meta: { show: true },
            // 二级路由组件
            children: [
                {
                    path: 'myorder',
                    component:MyOrder
                }, {
                    path: 'grouporder',
                    component:GroupOrder
                },
                {
                    path: '/center',
                    redirect:'/center/myorder'
                }
            ]
        },
        {
            //重定向时，项目跑起来的时候，访问 / ，立马让他定向到首页
            path: '*',
            redirect: '/home'
        }
    ]
